﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BL;
using DA;
using Entities;
using ERP.Membership;

namespace ERP
{
    public partial class AddItemToOrder : BaseERPPage
    {
        OrderItemManager orderItemManager = new OrderItemManager();

        public AddItemToOrder()
            : base(Permission.OrdersWrite)
        {

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownListItem.DataSource = orderItemManager.GetItems();
                DropDownListItem.DataTextField = "OrderItemName";
                DropDownListItem.DataValueField = "OrderItemId";
                DropDownListItem.DataBind();
                UserControlItemsReport.DataSourceU = orderItemManager.GetItemsInOrder(5);//Request.QueryString.Get("OrderId"));
            }
        }
        protected void btn_click_ButtonAddToOrder(object sender, EventArgs e)
        {
            ERP_ItemsInOrder item = new ERP_ItemsInOrder();
            item.OrderId = int.Parse(Request.QueryString.Get("OrderId"));
            item.OrderItemId = int.Parse(DropDownListItem.SelectedValue);
            item.Price = decimal.Parse(TextBoxItemPrice.Text);
            if (orderItemManager.AddItemToOrder(item))
            {
                Response.Redirect("OrderForm.aspx?OrderId=" + item.OrderId);
            }
        }
    }
}